
package com.lzx.iteam.util;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnShowListener;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.Html;
import android.text.InputType;
import android.text.Selection;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.*;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager.BadTokenException;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.*;
import android.widget.AdapterView.OnItemClickListener;
import com.baidu.mapapi.map.Text;
import com.lzx.iteam.R;
import com.lzx.iteam.adapter.DialogListAdapter;
import com.lzx.iteam.widget.Rotate3D;

import java.util.HashMap;

public class AllDialogUtil {

    public final static String TAG = "AllDialogUtil";

    static AllDialogUtil mDialogStyle;

    Activity mContext;

    DialogOnClickListener mListener;

    DialogBtnOnClickListner mBtnListener;

    EditDialogOnClickListener mEditListener;

    CheckBoxOnClickListener mCheckBoxListener;

    DialogOnCancelableListener mCancelableListener;

    DialogListOnClickListner mDialogListOnClickListner;

    DialogTextOnClick mDialogTextOnClick;

    DialogLoginOnClickListener mLoginListener;

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case Constants.MSG_DATA_READY:
                    if (msg != null) {
                        EditText editText = (EditText) msg.obj;
                        InputMethodManager inputMethodManager = ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE));
                        inputMethodManager.showSoftInput(editText, InputMethodManager.HIDE_NOT_ALWAYS);
                    }
                    break;
//                case Constants.MSG_CLOSE_INPUT:
//                    if(msg != null){
//                        EditText editText = (EditText) msg.obj;
//                        InputMethodManager inputMethodManager = ((InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE));
//                        if(inputMethodManager.isActive()){
//                            inputMethodManager.hideSoftInputFromWindow(editText.getWindowToken(),0);
//                        }
//                    }
//                    break;
            }
        }
    };

    public AllDialogUtil(Activity context) {
        this.mContext = context;
    }

    /**
     * 设计成单例模式，会有一个问题，如果最先实例化它的Activity销毁了，则后面Activity使用AllDialogUtil，均无法显示
     *
     * @param context
     * @return
     */
    public static AllDialogUtil getInstance(Activity context) {
        if (null == mDialogStyle) {
            return new AllDialogUtil(context);
        }
        return mDialogStyle;
    }

    public interface DialogOnCancelableListener {
        public void onCancelable(Dialog lDialog);
    }

    public interface DialogTextOnClick {
        public void onClick();
    }

    public interface DialogOnClickListener {
        public void onConfirmClick(Dialog lDialog);

        public void onCancelClick(Dialog lDialog);

    }

    public interface EditDialogOnClickListener {
        public void onConfirmClick(Dialog lDialog, EditText ed);

        public void onCancelClick(Dialog lDialog, EditText ed);
    }

    public interface CheckBoxOnClickListener {
        public void onConfirmClick(Dialog lDialog, CheckBox cb);

        public void onCancelClick(Dialog lDialog, CheckBox cb);
    }

    public interface DialogBtnOnClickListner {
        public void onBtnOnClick(View btn, Dialog lDialog);
    }

    public interface DialogListOnClickListner {
        public void onListItemClick(Dialog lDialog, int position);
    }

    public interface DialogLoginOnClickListener {

        public void onBtnOnClick(Dialog lDialog);
    }


    public void setOnDialogCancelableListener(DialogOnCancelableListener listener) {
        mCancelableListener = listener;
    }

    public void setOnDialogBtnListener(DialogBtnOnClickListner listener) {
        mBtnListener = listener;
    }

    public void setOnDialogListener(DialogOnClickListener listener) {
        mListener = listener;
    }

    public void setOnEditDialogListener(EditDialogOnClickListener listener) {
        mEditListener = listener;
    }

    public void setOnCheckBoxListener(CheckBoxOnClickListener listener) {
        mCheckBoxListener = listener;
    }

    public void setOnDialogListListener(DialogListOnClickListner listener) {
        mDialogListOnClickListner = listener;
    }

    public void setOnClickListner(DialogTextOnClick listner) {
        this.mDialogTextOnClick = listner;
    }

    public void setOnLoginListener(DialogLoginOnClickListener listener) {
        this.mLoginListener = listener;
    }


    /**
     * 普通的Dialog  message靠左侧
     * @param title
     * @param message
     * @param confirmText
     * @param cancelText
     * @return
     */
    public Dialog titleMsgBtnStyle(String title, String message, String confirmText,
                                   String cancelText) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.dialog_msg_title);
        TextView titleview = (TextView) lDialog.findViewById(R.id.tv_title);
        TextView msg = (TextView) lDialog.findViewById(R.id.tv_message);
        msg.setText(message);
        if(StringUtil.isEmpty(title)){
            titleview.setVisibility(View.GONE);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            layoutParams.setMargins(0,10,0,0);//4个参数按顺序分别是左上右下
            msg.setLayoutParams(layoutParams);
              }else{
            titleview.setText(title);
        }

//        if (title.contains("发现新版本")) {
            msg.setGravity(Gravity.LEFT);
//        }
        Button confirmBtn = (Button) lDialog.findViewById(R.id.btn_confirm);
        Button cancelBtn = (Button) lDialog.findViewById(R.id.btn_cancel);
        confirmBtn.setText(confirmText);
        cancelBtn.setText(cancelText);
        confirmBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mListener != null) {
                    mListener.onConfirmClick(lDialog);
                }
            }
        });

        cancelBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mListener != null) {
                    mListener.onCancelClick(lDialog);
                }
            }
        });
        lDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                if (mCancelableListener != null) {
                    mCancelableListener.onCancelable(lDialog);
                }
            }
        });

        try {
            lDialog.show();
        } catch (BadTokenException e) {
            Log.d(TAG, e.toString());
        }

        return lDialog;

    }

    /**
     * 只有一行字的Dialog
     * @param message
     * @param confirmText
     * @param cancelText
     * @return
     */
    public Dialog titleOneDialog(String message, String confirmText,String cancelText) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.dialog_msg_one);
        lDialog.setCanceledOnTouchOutside(true);
        TextView msg = (TextView) lDialog.findViewById(R.id.tv_one_message);
        msg.setText(message);
        Button confirmBtn = (Button) lDialog.findViewById(R.id.btn_one_confirm);
        Button cancelBtn = (Button) lDialog.findViewById(R.id.btn_one_cancle);
        confirmBtn.setText(confirmText);
        cancelBtn.setText(cancelText);
        confirmBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mListener != null) {
                    mListener.onConfirmClick(lDialog);
                }
            }
        });

        cancelBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mListener != null) {
                    mListener.onCancelClick(lDialog);
                }
            }
        });


        try {
            lDialog.show();
        } catch (BadTokenException e) {
            Log.d(TAG, e.toString());
        }

        return lDialog;

    }

    /**
     * 一般的Dialog
     * @param title
     * @param message
     * @param confirmText
     * @param cancelText
     * @return
     */
    public Dialog titleMsgBtnClick(String title, String message, String confirmText,
                                   String cancelText) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.dialog_msg_title);
        lDialog.setCanceledOnTouchOutside(true);
        TextView titleview = (TextView) lDialog.findViewById(R.id.tv_title);
        if (StringUtil.isEmpty(title)) {
            titleview.setVisibility(View.GONE);
        }else{
            titleview.setText(title);
        }
        TextView msg = (TextView) lDialog.findViewById(R.id.tv_message);
        msg.setText(message);
        msg.setGravity(Gravity.CENTER);
        msg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mDialogTextOnClick != null) {
                    mDialogTextOnClick.onClick();
                }
            }
        });
        Button confirmBtn = (Button) lDialog.findViewById(R.id.btn_confirm);
        Button cancelBtn = (Button) lDialog.findViewById(R.id.btn_cancel);
        confirmBtn.setText(confirmText);
        cancelBtn.setText(cancelText);
        confirmBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mListener != null) {
                    mListener.onConfirmClick(lDialog);
                }
            }
        });

        cancelBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mListener != null) {
                    mListener.onCancelClick(lDialog);
                }
            }
        });
        lDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                if (mCancelableListener != null) {
                    mCancelableListener.onCancelable(lDialog);
                }
            }
        });

        try {
            lDialog.show();
        } catch (BadTokenException e) {
            Log.d(TAG, e.toString());
        }

        return lDialog;

    }


    /**
     * 一般的Dialog 下面只有一个按钮
     * @param title
     * @param message
     * @param confirmText
     * @return
     */
    public Dialog titleMsgBtnStyle(String title, String message, String confirmText) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.dialog_msg_title);
        TextView titleview = (TextView) lDialog.findViewById(R.id.tv_title);
        titleview.setText(title);
        TextView msg = (TextView) lDialog.findViewById(R.id.tv_message);
        msg.setText(message);
        lDialog.findViewById(R.id.middle_line).setVisibility(View.GONE);
        Button confirmBtn = (Button) lDialog.findViewById(R.id.btn_confirm);
        Button cancelBtn = (Button) lDialog.findViewById(R.id.btn_cancel);
        confirmBtn.setText(confirmText);
        cancelBtn.setVisibility(View.GONE);
        confirmBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mListener != null) {
                    mListener.onConfirmClick(lDialog);
                }
            }
        });
        lDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                if (mCancelableListener != null) {
                    mCancelableListener.onCancelable(lDialog);
                }
            }
        });
        lDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                if (i == KeyEvent.KEYCODE_BACK) {
                    return true;
                } else {
                    return false;
                }
            }
        });

        if (!mContext.isFinishing() && !lDialog.isShowing()) {
            lDialog.show();
        }
        return lDialog;
    }

    /**
     * 删除提示框
     * @param confirmText
     * @param cancelText
     * @param message
     * @return
     */
    public Dialog titleDeleteMsgStyle(String confirmText,
                                      String cancelText, String message) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                        | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.setContentView(R.layout.dialog_delete_notitle_style);
//        DisplayMetrics dm = new DisplayMetrics();
//        mContext.getWindowManager().getDefaultDisplay().getMetrics(dm);
//        LinearLayout linearLayout = (LinearLayout) lDialog.findViewById(R.id.exit_chatgroup_layout);
//        LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) linearLayout.getLayoutParams();
//        linearParams.height = Constants.dip2px(mContext, 153);
//        linearParams.width = Constants.dip2px(mContext, Constants.px2dip(mContext, dm.widthPixels) - 32);
//        linearLayout.setLayoutParams(linearParams);
        TextView msg = (TextView) lDialog.findViewById(R.id.dialog_edit_msg);
        msg.setText(message);
        Button confirmBtn = (Button) lDialog.findViewById(R.id.edit_confirm_btn);
        Button cancelBtn = (Button) lDialog.findViewById(R.id.edit_cancel_btn);
        confirmBtn.setText(confirmText);
        cancelBtn.setText(cancelText);
        confirmBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onConfirmClick(lDialog);
                }

            }
        });

        cancelBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onCancelClick(lDialog);
                }

            }
        });

        lDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                if (mCancelableListener != null) {
                    mCancelableListener.onCancelable(lDialog);
                }
            }
        });
        try {
            lDialog.show();
        } catch (BadTokenException e) {
            Log.d(TAG, e.toString());
        }
        return lDialog;
    }


    /**
     *
     * @param title
     * @param confirmText
     * @param cancelText
     * @param message
     * @return
     */
    public Dialog titleDeleteMsgStyle(String title, String confirmText,
                                      String cancelText, String message) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                        | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        lDialog.setContentView(R.layout.dialog_delete_style);
       /* DisplayMetrics dm = new DisplayMetrics();
        mContext.getWindowManager().getDefaultDisplay().getMetrics(dm);
        LinearLayout linearLayout = (LinearLayout) lDialog.findViewById(R.id.exit_group_layout);
        LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) linearLayout.getLayoutParams();
        linearParams.height = Constants.dip2px(mContext, 153);
        linearParams.width = Constants.dip2px(mContext, Constants.px2dip(mContext, dm.widthPixels) - 32);
        linearLayout.setLayoutParams(linearParams);*/

        TextView titleview = (TextView) lDialog.findViewById(R.id.dialog_edit_title);
        titleview.setText(title);
        TextView msg = (TextView) lDialog.findViewById(R.id.dialog_edit_msg);
        msg.setText(message);
        Button confirmBtn = (Button) lDialog.findViewById(R.id.edit_confirm_btn);
        Button cancelBtn = (Button) lDialog.findViewById(R.id.edit_cancel_btn);
        confirmBtn.setText(confirmText);
        cancelBtn.setText(cancelText);
        confirmBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onConfirmClick(lDialog);
                }

            }
        });

        cancelBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onCancelClick(lDialog);
                }

            }
        });

        lDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                if (mCancelableListener != null) {
                    mCancelableListener.onCancelable(lDialog);
                }
            }
        });
        try {
            lDialog.show();
        } catch (BadTokenException e) {
            Log.d(TAG, e.toString());
        }
        return lDialog;
    }

    /**
     * 带输入框的Dialog
     * @param title
     * @param editText
     * @param confirmText
     * @param cancelText
     * @param message
     * @return
     */
    public Dialog titleEditBtnStyle(String title, String editText, String confirmText,
                                    String cancelText, String message) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                        | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        lDialog.setContentView(R.layout.dialog_edit_style);
        TextView titleview = (TextView) lDialog.findViewById(R.id.dialog_edit_title);
        titleview.setText(title);
        TextView msg = (TextView) lDialog.findViewById(R.id.dialog_edit_msg);
        final EditText ed = (EditText) lDialog.findViewById(R.id.dialog_edit);
        if (!StringUtil.isEmpty(editText)) {
            ed.setText(editText);
        } else {
//            ed.setHint("组名");
        }
        ed.setMaxEms(11);
        Editable editable = ed.getText();
        Selection.setSelection(editable, 0, editable.length());
        setAutoShowKey(ed, true);
        if (StringUtil.isEmpty(message)) {
            msg.setVisibility(View.GONE);
        } else {
            msg.setText(message);
        }
        Button confirmBtn = (Button) lDialog.findViewById(R.id.edit_confirm_btn);
        Button cancelBtn = (Button) lDialog.findViewById(R.id.edit_cancel_btn);
        confirmBtn.setText(confirmText);
        cancelBtn.setText(cancelText);
        confirmBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mEditListener != null) {
                    if (ed.getText().toString() != null && ed.getText().toString().length() > 0) {
                        mEditListener.onConfirmClick(lDialog, ed);
                        setAutoShowKey(ed, false);
                    } else {
                        // 输入框抖动
                        Animation shake = AnimationUtils.loadAnimation(mContext, R.anim.shake);
                        ed.startAnimation(shake);
                    }
                }
            }
        });

        cancelBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mEditListener != null) {
                    mEditListener.onCancelClick(lDialog, ed);
                    setAutoShowKey(ed, false);
                }
            }
        });

        lDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                if (mCancelableListener != null) {
                    mCancelableListener.onCancelable(lDialog);
                    setAutoShowKey(ed, false);
                }
            }
        });
        try {
            lDialog.show();
        } catch (BadTokenException e) {
            Log.d(TAG, e.toString());
        }
        return lDialog;
    }

    /**
     * 带输入框的Dialog
     * @param title
     * @param editText
     * @param confirmText
     * @param cancelText
     * @param message
     * @return
     */
    public Dialog approvalEditStyle(String title, String editText, String confirmText,
                                    String cancelText, String message) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                        | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        lDialog.setContentView(R.layout.dialog_edit_style);
        TextView titleview = (TextView) lDialog.findViewById(R.id.dialog_edit_title);
        if (StringUtil.isEmpty(title)) {
            titleview.setVisibility(View.GONE);
        } else {
            titleview.setText(title);
        }
        TextView msg = (TextView) lDialog.findViewById(R.id.dialog_edit_msg);
        if (StringUtil.isEmpty(message)){
            msg.setVisibility(View.GONE);
        }else{
            msg.setText(message);
        }
        final EditText ed = (EditText) lDialog.findViewById(R.id.dialog_edit);
        if (!StringUtil.isEmpty(editText)) {
            ed.setHint(editText);
        }
        ed.setMaxLines(4);

        Button confirmBtn = (Button) lDialog.findViewById(R.id.edit_confirm_btn);
        Button cancelBtn = (Button) lDialog.findViewById(R.id.edit_cancel_btn);
        confirmBtn.setText(confirmText);
        cancelBtn.setText(cancelText);
        confirmBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mEditListener != null) {
                    mEditListener.onConfirmClick(lDialog, ed);
                }
            }
        });

        cancelBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mEditListener != null) {
                    mEditListener.onCancelClick(lDialog, ed);
                    setAutoShowKey(ed, false);
                }
            }
        });

        lDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                if (mCancelableListener != null) {
                    mCancelableListener.onCancelable(lDialog);
                    setAutoShowKey(ed, false);
                }
            }
        });
        try {
            lDialog.show();
        } catch (BadTokenException e) {
            Log.d(TAG, e.toString());
        }
        return lDialog;
    }

    /**
     * 带输入框的Dialog
     * @param title
     * @param editText
     * @param confirmText
     * @param cancelText
     * @param message
     * @return
     */
    public Dialog salaryEditStyle(String title, String editText, String confirmText,
                                    String cancelText, String message,int inputType) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.getWindow().setSoftInputMode(
              WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                    | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        lDialog.setContentView(R.layout.dialog_edit_salary_layout);
        TextView titleview = (TextView) lDialog.findViewById(R.id.dialog_edit_title);
        if (StringUtil.isEmpty(title)) {
            titleview.setVisibility(View.GONE);
        } else {
            titleview.setText(title);
        }
        TextView msg = (TextView) lDialog.findViewById(R.id.dialog_edit_msg);
        if (StringUtil.isEmpty(message)){
            msg.setVisibility(View.GONE);
        }else{
            msg.setText(message);
        }
        final EditText ed = (EditText) lDialog.findViewById(R.id.dialog_edit);
        if (editText != null) {
            ed.setText(StringUtil.floatFormat(editText,true));
        }
        ed.setSingleLine();
        Editable editable = ed.getText();
        Selection.setSelection(editable, 0, editable.length());
        setAutoShowKey(ed,true);

        if (inputType == 0){
            ed.setInputType(InputType.TYPE_CLASS_NUMBER|InputType.TYPE_NUMBER_FLAG_DECIMAL);
        }else{

        }

        Button confirmBtn = (Button) lDialog.findViewById(R.id.edit_confirm_btn);
        Button cancelBtn = (Button) lDialog.findViewById(R.id.edit_cancel_btn);
        confirmBtn.setText(confirmText);
        cancelBtn.setText(cancelText);

        ed.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (mEditListener != null) {
                    mEditListener.onConfirmClick(lDialog, ed);
                }
                return true;
            }
        });

        confirmBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mEditListener != null) {
                    mEditListener.onConfirmClick(lDialog, ed);
                }
            }
        });

        cancelBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mEditListener != null) {
                    mEditListener.onCancelClick(lDialog, ed);
                    setAutoShowKey(ed, false);
                }
            }
        });

        lDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                if (mCancelableListener != null) {
                    mCancelableListener.onCancelable(lDialog);
                    setAutoShowKey(ed, false);
                }
            }
        });
        try {
            lDialog.show();
        } catch (BadTokenException e) {
            Log.d(TAG, e.toString());
        }
        return lDialog;
    }



    public Dialog titleMsgBtnStyleTextClick(String title, String message, String confirmText,
                                            String cancelText) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.dialog_msg_title);
        TextView titleview = (TextView) lDialog.findViewById(R.id.tv_title);
        titleview.setText(title);
        TextView msg = (TextView) lDialog.findViewById(R.id.tv_message);
        msg.setText(Html.fromHtml("<a href=\"http://blog.csdn.net/CAIYUNFREEDOM\">" + message + "</a>"));
        msg.setGravity(Gravity.CENTER_HORIZONTAL);
        msg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mDialogTextOnClick != null) {
                    mDialogTextOnClick.onClick();
                }
            }
        });
        Button confirmBtn = (Button) lDialog.findViewById(R.id.btn_confirm);
        Button cancelBtn = (Button) lDialog.findViewById(R.id.btn_cancel);
        confirmBtn.setText(confirmText);
        cancelBtn.setText(cancelText);
        confirmBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mListener != null) {
                    mListener.onConfirmClick(lDialog);
                }
            }
        });

        cancelBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mListener != null) {
                    mListener.onCancelClick(lDialog);
                }
            }
        });
        lDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                if (mCancelableListener != null) {
                    mCancelableListener.onCancelable(lDialog);
                }
            }
        });

        try {
            lDialog.show();
        } catch (BadTokenException e) {
            Log.d(TAG, e.toString());
        }

        return lDialog;

    }

    public Dialog checkTextClick(String title, String message, String confirmText,
                                 String cancelText) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.dialog_msg_title);
        TextView titleview = (TextView) lDialog.findViewById(R.id.tv_title);
        final CheckBox checkBox = (CheckBox) lDialog.findViewById(R.id.privacy_agreement_check);
        checkBox.setVisibility(View.VISIBLE);
        titleview.setText(title);
        TextView msg = (TextView) lDialog.findViewById(R.id.tv_message);
        msg.setText(Html.fromHtml("<a href=\"\">" + message + "</a>"));
        msg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mDialogTextOnClick != null) {
                    mDialogTextOnClick.onClick();
                }
            }
        });
        Button confirmBtn = (Button) lDialog.findViewById(R.id.btn_confirm);
        Button cancelBtn = (Button) lDialog.findViewById(R.id.btn_cancel);
        confirmBtn.setText(confirmText);
        cancelBtn.setText(cancelText);
        confirmBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (!checkBox.isChecked()) {
                    Toast.makeText(mContext, mContext.getString(R.string.validate_second_privacy_agreement), Toast.LENGTH_SHORT).show();
                    return;
                }
                if (mListener != null) {
                    mListener.onConfirmClick(lDialog);
                }

            }
        });

        cancelBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mListener != null) {
                    mListener.onCancelClick(lDialog);
                }
            }
        });
        lDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                if (mCancelableListener != null) {
                    mCancelableListener.onCancelable(lDialog);
                }
            }
        });
        try {
            lDialog.show();
        } catch (BadTokenException e) {
            Log.d(TAG, e.toString());
        }
        return lDialog;
    }



/*
    public Dialog titleMsgBtnStyle(String title, String message, String confirmText, boolean isCenter) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.dialog_msg_title);
        TextView titleview = (TextView) lDialog.findViewById(R.id.tv_title);
        titleview.setText(title);
        TextView msg = (TextView) lDialog.findViewById(R.id.tv_message);
        if (isCenter) {
            msg.setGravity(Gravity.CENTER_HORIZONTAL);
        }
        msg.setText(message);
        lDialog.findViewById(R.id.middle_line).setVisibility(View.GONE);
        Button confirmBtn = (Button) lDialog.findViewById(R.id.btn_confirm);
        Button cancelBtn = (Button) lDialog.findViewById(R.id.btn_cancel);
        confirmBtn.setText(confirmText);
        cancelBtn.setVisibility(View.GONE);
        confirmBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mListener != null) {
                    mListener.onConfirmClick(lDialog);
                }
            }
        });
        lDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                if (mCancelableListener != null) {
                    mCancelableListener.onCancelable(lDialog);
                }
            }
        });

        if (!mContext.isFinishing()) {
            lDialog.show();
        }
        return lDialog;
    }
*/





    public Dialog styleProgress(String text) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.style_progress);
        final TextView tv_text = (TextView) lDialog.findViewById(R.id.tv_msg_wait);
        tv_text.setText(text);
        final ImageView progress = (ImageView) lDialog.findViewById(R.id.iv_progress);
        lDialog.setOnShowListener(new OnShowListener() {

            @Override
            public void onShow(DialogInterface dialog) {
                final float centerX = progress.getWidth() / 2.0f;
                final float centerY = progress.getHeight() / 2.0f;
                Rotate3D rotate3d = new Rotate3D(0, 360, 0, 0, centerX, centerY);
                rotate3d.setDuration(1000);
                rotate3d.setRepeatMode(Animation.RESTART);
                rotate3d.setRepeatCount(Animation.INFINITE);
                rotate3d.setFillAfter(true);
                progress.startAnimation(rotate3d);

            }
        });
        lDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialogInterface) {
                mContext.finish();
            }
        });
        return lDialog;
    }

    public Dialog queryNetDialog() {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.wait_layout);
        /*lDialog.setOnShowListener(new OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {

            }
        });*/
        lDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialogInterface) {
                mContext.finish();
            }
        });
        return lDialog;
    }


    public Dialog waitDialog() {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.wait_layout);
        /*lDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialogInterface) {
                mContext.finish();
            }
        });*/
        return lDialog;
    }

    public Dialog waitDialog(String msg) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.wait_layout);
        TextView waitText=(TextView)lDialog.findViewById(R.id.tv_wait_dialog_text);
        if(!StringUtil.isEmpty(msg)){
            waitText.setText(msg);
        }
        /*lDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialogInterface) {
                mContext.finish();
            }
        });*/
        return lDialog;
    }


    public Dialog whiteDialog(String[] buttons) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.dialog_white);
        final ListView listview = (ListView) lDialog.findViewById(R.id.btn_list);
        DialogListAdapter adapter = new DialogListAdapter(mContext);
        adapter.setData(buttons);
        listview.setAdapter(adapter);
        listview.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (mDialogListOnClickListner != null) {
                    mDialogListOnClickListner.onListItemClick(lDialog, position);
                }
            }

        });
        return lDialog;
    }

    public Dialog whiteDialog(String title, String[] buttons) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.dialog_white);
        LinearLayout containerTitle = (LinearLayout) lDialog.findViewById(R.id.container_title);
        containerTitle.setVisibility(View.VISIBLE);
        TextView tvTitle = (TextView) lDialog.findViewById(R.id.tv_title);
        tvTitle.setTextColor(0xff000000);
        tvTitle.setText(title);
        final ListView listview = (ListView) lDialog.findViewById(R.id.btn_list);
        DialogListAdapter adapter = new DialogListAdapter(mContext);
        adapter.setData(buttons);
        listview.setAdapter(adapter);
        listview.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (mDialogListOnClickListner != null) {
                    mDialogListOnClickListner.onListItemClick(lDialog, position);
                }
            }

        });
        return lDialog;
    }

    public Dialog sbDialog(String title, String text, String[] buttons) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.sb_dialog_layout);
        final ListView listview = (ListView) lDialog.findViewById(R.id.btn_list);
        DialogListAdapter adapter = new DialogListAdapter(mContext);
        TextView tv_title = (TextView) lDialog.findViewById(R.id.tv_cloud_title);
        tv_title.setText(title);
        adapter.setData(buttons);
        listview.setAdapter(adapter);
        listview.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (mDialogListOnClickListner != null) {
                    mDialogListOnClickListner.onListItemClick(lDialog, position);
                }
            }

        });
        return lDialog;
    }

    /**
     * 中间内容为EditText的dialog
     *
     * @param titleText 标题
     * @param hintText  输入提示文字
     * @param inputType 输入类型 1:电话号码 ，2:密码，3:所有字符
     * @return lDialog
     */
    public Dialog etDialog(String titleText, String hintText, int inputType) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.et_dialog_layout);
        TextView tv_title = (TextView) lDialog.findViewById(R.id.tv_title);
        tv_title.setText(titleText);
        final EditText et_content = (EditText) lDialog.findViewById(R.id.et_content);
        et_content.setFocusable(true);
        switch (inputType) {
            case 1://电话
                et_content.setInputType(InputType.TYPE_CLASS_PHONE);
                break;
            case 2://密码
                et_content.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                break;
            case 3://字符
                et_content.setInputType(InputType.TYPE_CLASS_TEXT);
                break;
        }
        final Button btn_close = (Button) lDialog.findViewById(R.id.btn_close);
        et_content.setHint(hintText);
        et_content.setHintTextColor(Color.GRAY);
        LinearLayout ll_confirm = (LinearLayout) lDialog.findViewById(R.id.tv_confirm);
        ll_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mEditListener != null) {
                    mEditListener.onConfirmClick(lDialog, et_content);
                }
            }
        });

        btn_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mEditListener != null) {
                    mEditListener.onCancelClick(lDialog, et_content);
//                    Message message = new Message();
//                    message.obj = et_content;
//                    message.what = Constants.MSG_CLOSE_INPUT;
//                    mHandler.sendMessage(message);
                }
            }
        });
        Message message = new Message();
        message.obj = et_content;
        message.what = Constants.MSG_DATA_READY;
        mHandler.sendMessageDelayed(message, 1000);
        return lDialog;
    }

    /**
     * 一行字，一个按钮
     * @param message
     * @param confirmText
     * @return
     */
    public Dialog dialogOneBtnStyle( String message, String confirmText) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.dialog_one_btn);
        TextView msg = (TextView) lDialog.findViewById(R.id.tv_dialog_message);
        msg.setText(message);
        Button confirmBtn = (Button) lDialog.findViewById(R.id.btn_dialog1_confirm);
        confirmBtn.setText(confirmText);
        confirmBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mListener != null) {
                    mListener.onConfirmClick(lDialog);
                }
            }
        });
        lDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                if (mCancelableListener != null) {
                    mCancelableListener.onCancelable(lDialog);
                }
            }
        });
        lDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                if (i == KeyEvent.KEYCODE_BACK) {
                    return true;
                } else {
                    return false;
                }
            }
        });

        if (!mContext.isFinishing()) {
            lDialog.show();
        }
        return lDialog;
    }

    /**
     * 中间类容为CheckBox的dialog
     *
     * @param titleText   标题文字
     * @param cbText      选择框提示文字
     * @param confirmText 确定按钮文字
     * @param cancelText  取消按钮文字
     * @return lDialog
     */
    public Dialog cbDialog(String titleText, String cbText, String confirmText, String cancelText) {
        final Dialog lDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
        WindowManager.LayoutParams lp = lDialog.getWindow().getAttributes();
        lp.dimAmount = 0.4f;
        lDialog.getWindow().setAttributes(lp);
        lDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.cb_dialog_layout);

        TextView tv_title = (TextView) lDialog.findViewById(R.id.tv_title);
        final CheckBox cb_choice = (CheckBox) lDialog.findViewById(R.id.cb_choice);
        TextView tv_confirm = (TextView) lDialog.findViewById(R.id.tv_ok);
        TextView tv_cancel = (TextView) lDialog.findViewById(R.id.tv_cancel);

        tv_title.setText(titleText);
        cb_choice.setText(cbText);
        tv_confirm.setText(confirmText);
        tv_cancel.setText(cancelText);

        tv_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mCheckBoxListener != null) {
                    mCheckBoxListener.onConfirmClick(lDialog, cb_choice);
                }
            }
        });

        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mCheckBoxListener != null) {
                    mCheckBoxListener.onCancelClick(lDialog, cb_choice);
                }
            }
        });
        return lDialog;
    }

    private void setButtonParams(Context context, Button btn) {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                Constants.dip2px(context, 40));
        params.weight = 1.0f;
        params.gravity = Gravity.CENTER_VERTICAL;
        params.setMargins(0, 0, 0, Constants.dip2px(context, 10));
        btn.setLayoutParams(params);
        btn.setTextSize(14);
        btn.setTag("top_button");
        btn.setBackgroundResource(R.drawable.bulksms_blue_btn_sel);
        btn.setTextColor(0xFFFFFFFF);
    }


    /**
     * 弹出软键盘
     */
    private void setAutoShowKey(final EditText ed, boolean isShow) {
        if (isShow) {
            ed.postDelayed(new Runnable() {

                @Override
                public void run() {
                    InputMethodManager im = (InputMethodManager) mContext
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    im.showSoftInput(ed, 0);
                }
            }, 200);
            Selection.setSelection(ed.getText(), ed.getText().toString().length());
        } else {
            ed.postDelayed(new Runnable() {

                @Override
                public void run() {
                    InputMethodManager im = (InputMethodManager) mContext
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    im.hideSoftInputFromWindow(ed.getWindowToken(), 0);
                }
            }, 200);
        }
    }

    public static Drawable getImageByStatus(Context context, long contactId) {
        Resources res = context.getResources();
        Drawable result = null;
        HashMap<Long, Integer> userStatus = (HashMap<Long, Integer>)
                PreferenceUtil.getInstance(context).getCloudContact(PreferenceUtil.CONTACT_ID_2_DIST_STATUS);
        if (userStatus != null) {
            Integer status = userStatus.get(contactId);
            if (status != null) {
                if (status != 0) {
                    if (isReaded(status)) {
                        int realStatus = AllDialogUtil.getRealStatus(status);
                        switch (realStatus) {
                            case 0:
                                result = res.getDrawable(R.drawable.tongxingzheng);
                                break;
                            case 1:
                                result = res.getDrawable(R.drawable.status_busy);
                                break;
                            case 2:
                                result = res.getDrawable(R.drawable.sina);
                                break;
                            case 3:
                                result = res.getDrawable(R.drawable.icon_location);
                                break;
                            default:
                                result = res.getDrawable(R.drawable.tongxingzheng);
                                break;
                        }
                    } else {
                        result = res.getDrawable(R.drawable.status_idle);
                    }
                } else {
                    result = res.getDrawable(R.drawable.tongxingzheng);
                }
            }
        }

        return result;
    }

    public static Bitmap getBitmapByStatus(Context context, long contactId) {
        Resources res = context.getResources();
        Bitmap result = null;
        HashMap<Long, Integer> userStatus = (HashMap<Long, Integer>)
                PreferenceUtil.getInstance(context).getCloudContact(PreferenceUtil.CONTACT_ID_2_DIST_STATUS);
        Integer status = userStatus.get(contactId);
        if (status != null) {
            if (status != 0) {
                if (isReaded(status)) {
                    int realStatus = AllDialogUtil.getRealStatus(status);
                    switch (realStatus) {
                        case 0:
                            result = BitmapFactory.decodeResource(res, R.drawable.tongxingzheng);
                            break;
                        case 1:
                            result = BitmapFactory.decodeResource(res, R.drawable.status_busy);
                            break;
                        case 2:
                            result = BitmapFactory.decodeResource(res, R.drawable.sina);
                            break;
                        case 3:
                            result = BitmapFactory.decodeResource(res, R.drawable.icon_location);
                            break;
                        default:
                            result = BitmapFactory.decodeResource(res, R.drawable.tongxingzheng);
                            break;
                    }
                } else {
                    result = BitmapFactory.decodeResource(res, R.drawable.status_idle);
                }
            } else {
                result = BitmapFactory.decodeResource(res, R.drawable.tongxingzheng);
            }
        }


        return result;
    }

    public static int setUnReaded(int status) {
        return (status | 0x80);
    }

    public static int setReaded(int status) {
        return (status & 0x7f);
    }

    public static boolean isReaded(int status) {
        if (status < 8) {
            return true;
        }
        return (status | 0x80) >> 7 == 0;
    }

    public static int getRealStatus(int status) {
        return (status & 0x7f);
    }

}
